read()) !== false) { if (($entry != ".") && ($entry != "..")) { if (is_dir("$source_dir/$entry")) { make_file_list("$source_dir/$entry", $list); } else if (is_file("$source_dir/$entry")) { //$list[] = mb_convert_encoding("$source_dir/$entry", 'UTF-8', 'Windows-1251'); $list[] = "$source_dir/$entry"; } } } } function make_dir_list($source_dir, &$list, $max_level = -1) { $dir = dir($source_dir); while (($entry = $dir->read()) !== false) { if (($entry != ".") && ($entry != "..")) { if (is_dir("$source_dir/$entry")) { if ($max_level > 1) make_dir_list("$source_dir/$entry", $list, $max_level - 1); else if ($max_level == -1) make_dir_list("$source_dir/$entry", $list); $list[] = mb_convert_encoding("$source_dir/$entry", 'UTF-8', 'Windows-1251'); } } } } function delete_directory($dirname) { if (is_dir($dirname)) $dir_handle = opendir($dirname); if (!$dir_handle) return false; while($file = readdir($dir_handle)) { if ($file != "." && $file != "..") { if (!is_dir($dirname."/".$file)) unlink($dirname."/".$file); else delete_directory($dirname.'/'.$file); } } closedir($dir_handle); rmdir($dirname); return true; } function copy_directory($source, $destination) { if (is_dir($source)) { @mkdir($destination); $directory = dir($source); while (false !== ($readdirectory = $directory->read())) { if ($readdirectory == '.' || $readdirectory == '..') { continue; } $PathDir = $source.'/'.$readdirectory; if (is_dir($PathDir)) { copy_directory($PathDir, $destination.'/'.$readdirectory); continue; } copy($PathDir, $destination.'/'.$readdirectory); } $directory->close(); } else { copy($source, $destination); } } ?> $block) $blocks[$i]['link'] = get_category_link($block['id']); $options = get_option('template_options'); // Инициализация глобальных переменных $_SERVER['global']['type'] = 'default'; $_SERVER['global']['blocks'] = $blocks; $_SERVER['global']['options'] = $options; // Определение типа страницы if (preg_match("|^[/]?video|Uis", $_SERVER['REQUEST_URI'])) { $_SERVER['global']['type'] = 'video'; } if (preg_match("|^[/]?katalog|Uis", $_SERVER['REQUEST_URI'])) { $_SERVER['global']['type'] = 'catalog'; } // Переадресация шаблона поиска add_filter('search_template', 'search_redirect'); function search_redirect($template) { $tmpl = locate_template('archive.php'); return $tmpl ? $tmpl : $template; } /* ================================================================================ Сайдбары ================================================================================ */ if (function_exists('register_sidebar')) register_sidebar(array('name' => 'right', 'description' => 'Правая колонка', 'before_widget' => '
', 'before_title' => '
', 'after_title' => '
' )); /* if (function_exists('register_sidebar')) register_sidebar(array('name' => 'footer', 'description' => 'Подвал', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '
', 'after_title' => '
' )); */ /* ================================================================================ Функции шаблона ================================================================================ */ // Вывод кода из админки function map_banner($name, $size = '768x90') { global $options; return $options[$name]; } // Вывод даты в кастом формате function my_post_date_simple($post_id = -1) { global $post; $p = $post; if ($post_id > 0) $p = get_post($post_id); $months = array('Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек'); $date = $p->post_date; if (preg_match("/([0-9]+)-([0-9]+)-([0-9]+)[\r\n\t ]*([0-9]+):([0-9]+):([0-9]+)/i", $date, $date)) { $year = $date[1]; $month = $date[2] - 1; $month = $months[$date[2] - 1]; $day = $date[3]; //$date = "$day $month $year"; $date = '
'; $date .= '
'; $date .= ' '.$day; $date .= '
'; $date .= '
'; $date .= ' '.$month; $date .= '
'; $date .= '
'; return $date; } else return false; } // Вывод даты в текстовом формате function my_post_date_text($post_id = -1) { global $post; $p = $post; if ($post_id > 0) $p = get_post($post_id); $months = array('января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'); $date = $p->post_date; if (preg_match("/([0-9]+)-([0-9]+)-([0-9]+)[\r\n\t ]*([0-9]+):([0-9]+):([0-9]+)/i", $date, $date)) { $year = $date[1]; $month = $date[2] - 1; $month = $months[$date[2] - 1]; $day = $date[3]; $date = "$day $month $year"; return $date; } else return false; } // Вывод даты в числовом формате function my_post_date_numerical() { global $post; $date = $post->post_date; if (preg_match("/([0-9]+)-([0-9]+)-([0-9]+)[\r\n\t ]*([0-9]+):([0-9]+):([0-9]+)/i", $date, $date)) { $year = $date[1]; $month = $date[2]; if (strlen($month) == 1) $month = "0".$month; $day = $date[3]; $date = "$day.$month.$year"; return $date; } else return false; } // Вывод времени function my_post_time() { global $post; $time = $post->post_date; if (preg_match("/([0-9]+)-([0-9]+)-([0-9]+)[\r\n\t ]*([0-9]+):([0-9]+):([0-9]+)/i", $time, $time)) { $hour = $time[4]; $minute = $time[5]; $second = $time[6]; $time = "$hour:$minute"; return $time; } else return false; } // Название родительской рубрики поста function my_category_name() { global $category_name; foreach (get_categories() as $allcat) if ($allcat -> slug == $category_name) { $cat_name = $allcat -> cat_name; return $cat_name; } return false; } // Текстовое превью function my_post_preview($symb_count = 50, $post_id = -1) { global $post; $content = $post->post_content; if ($post_id > 0) { $p = get_post($post_id); $content = $p -> post_content; } $content = strip_tags($content); //$content = preg_replace("/([аеёийоуыэюя]{1})/", "$1­", $content); preg_match_all('/[\r\n\t ]*([^.?!]+[.?!]{1})/i', $content, $sent); $sent = implode(" ", $sent[1]); $res = ''; $words = explode(" ", $sent); foreach ($words as $word) { if (mb_strlen(trim($res).' '.$word) > $symb_count) break; $res .= ' '.$word; } if (!preg_match("/[.?!]{1}\$/i", $res)) $res .= '...'; return trim($res); } // Миниатюра (картинка превью) function my_post_thumb($width, $height, $class = '') { global $post; $attachments = get_posts(array('post_type' => 'attachment', 'numberposts' => -1, 'post_parent' => $post->ID)); $meta = get_post_meta($post->ID, 'youtube_video_id', true); if ($attachments || $meta) { $src = 'http://img.youtube.com/vi/'.$meta.'/mqdefault.jpg'; if (!$meta) { $src = wp_get_attachment_image_src($attachments[0]->ID); $src = $src[0]; $src = str_replace(get_bloginfo('url'), '', $src); $src = preg_replace("/-[0-9]+x[0-9]+\.(jpg|jpeg|png|gif)/Uis", ".$1", $src); } $src = get_stylesheet_directory_uri().'/timthumb.php?src='.$src.'&w='.$width.'&h='.$height.'&zc=1'; $title = my_post_title(); return "\"$title\""; } } // Заголовок поста function my_post_title($length = 0, $post_id = -1) { global $post; $p = $post; if ($post_id > 0) $p = get_post($post_id); $title = $p->post_title; $res = $title; if ($length > 0 && mb_strlen($title) > $length) $res = mb_substr($title, 0, $length)."..."; return trim($res); } // Категория поста function my_post_category() { global $post; ob_start(); the_category(' • '); $category = ob_get_clean(); return $category; } // Автор поста function my_post_author() { global $post; $author = 'admin'; return $author; } // Количество комментариев к посту function my_post_comments_number() { global $post; ob_start(); comments_number('Комментариев нет', '1 комментарий','Комментарии (%)'); $comments = ob_get_clean(); return $comments; } // Заголовок окна браузера function my_window_title() { return 'Default Title'; } // Вывод блока function my_block($params) { global $wpdb, $post; $category = isset($params['category']) ? $params['category'] : ''; $count = isset($params['count']) ? $params['count'] : 5; $offset = isset($params['offset']) ? $params['offset'] : 0; //$orderby = isset($params['orderby']) ? $params['order'] : 'date'; //$order = isset($params['order']) ? $params['order'] : 'desc'; $orderby = 'date'; $order = 'desc'; $include = ''; $template = isset($params['template']) ? $params['template'] : ''; if (isset($params['related'])) { $category = get_the_category($params['related']); $category = $category[0]->cat_ID; $orderby = 'rand'; } if (isset($params['include'])) { $params['category'] = ''; $include = $params['include']; } // Сохраняем исходный пост $post_src = $post; $posts = get_posts(array( 'numberposts' => $count, 'category' => $category, 'include' => $include, 'offset' => $offset, 'orderby' => 'date', 'order' => $order )); $result = ''; foreach ($posts as $post) { setup_postdata($post); // Парсим шаблон $t = $template; // URL $t = str_replace('{link}', get_permalink(), $t); // Категория, автор, количество комментариев $t = str_replace('{category}', my_post_category(), $t); $t = str_replace('{author}', my_post_author(), $t); $t = str_replace('{comments_number}', get_comments_number(), $t); $t = str_replace('{comments}', my_post_comments_number(), $t); // Дополнительные поля while (preg_match("/\{meta\|(.*)\}/Uis", $t, $match)) { $t = str_replace($match[0], get_post_meta($post->ID, $match[1], true), $t); } // Время $t = str_replace('{time}', my_post_time(), $t); // Дата while (preg_match("/\{date\|(.*)\}/Uis", $t, $match)) { if ($match[1] == 'simple') $t = str_replace($match[0], my_post_date_simple(), $t); else if ($match[1] == 'text') $t = str_replace($match[0], my_post_date_text(), $t); else $t = str_replace($match[0], my_post_date_numerical(), $t); } // Заголовок while (preg_match("/\{title\|(.*)\}/Uis", $t, $match)) { $t = str_replace($match[0], my_post_title($match[1]), $t); } // Текстовое превью while (preg_match("/\{excerpt\|(.*)\}/Uis", $t, $match)) { $t = str_replace($match[0], my_post_preview($match[1]), $t); } // Текстовое превью каталога while (preg_match("/\{catalog_excerpt\|(.*)\}/Uis", $t, $match)) { $catalog_excerpt = get_the_content(); preg_match("/\(.*)\<\/table\>/Uis", $catalog_excerpt, $catalog_excerpt); preg_match_all("/\[\r\n\t ]*\(.+)\<\/td\>[\r\n\t ]*\<\/tr\>[\r\n\t ]*\[\r\n\t ]*\(.+)\<\/td\>[\r\n\t ]*\<\/tr\>/Uis", $catalog_excerpt[1], $catalog_excerpt); $catalog_excerpt = $catalog_excerpt[1][1].$catalog_excerpt[2][1]; $t = str_replace($match[0], $catalog_excerpt, $t); } // Полный текст while (preg_match("/\{content\}/Uis", $t, $match)) { $t = str_replace($match[0], get_the_content(), $t); } // Картинка while (preg_match("/\{thumbnail\|(.*)\|(.*)\|(.*)\}/Uis", $t, $match)) { $t = str_replace($match[0], my_post_thumb($match[1], $match[2], $match[3]), $t); } $result .= $t; } // Восстанавливаем исходный пост $post = $post_src; setup_postdata($post); return $result; } function map_block_prefix($block, $is_recursive = false) { $block_prefix = substr($block, 0, 1); $block_html = $block; if ($block_prefix == 't') { preg_match("/^t([0-9]+)/is", $block, $block_modifiers); $title_length = $block_modifiers[1] ? $block_modifiers[1] : 0; $block_html = '{title|'.$title_length.'}'; } if ($block_prefix == 'm') { preg_match("/^m([a-z]?)([a-z]?)([a-z]?)([a-z]?)/is", $block, $block_modifiers); /* $meta_types = array( 'default' => '
  • {date|text}
  • ', 'd' => '
  • {date|text}
  • ', 'D' => '
  • {date|numerical}
  • ', 't' => '
  • {time}
  • ', 'c' => '
  • {category}
  • ', 'r' => '
  • {comments_number}
  • ' ); */ $block_html = '
      '; if ($is_recursive) { $block_html = '
        '; } unset($block_modifiers[0]); if (!$block_modifiers[1]) $block_modifiers = array('default'); foreach ($block_modifiers as $block_modifier) { $block_html .= $meta_types[$block_modifier]; } $block_html .= '
      '; } if ($block_prefix == 'p') { $is_suberthumb = false; $block_meta_html = ''; $block_clear = $block; if (preg_match("/^p[^{}]*{([^}]+)}[^{}]*/is", $block, $block_modifiers)) { $block_clear = str_replace('{'.$block_modifiers[1].'}', '', $block_clear); $is_suberthumb = true; $block_meta_html = map_block_prefix($block_modifiers[1], true); } preg_match("/^p([x0-9]+)/is", $block_clear, $block_modifiers); $size = $block_modifiers[1] ? $block_modifiers[1] : '100x100'; $size = explode('x', $size); if ($is_suberthumb) { $block_html = '
      {thumbnail|'.$size[0].'|'.$size[1].'|thumb f_l}
    '.$block_meta_html.'
    '; } else $block_html = '{thumbnail|'.$size[0].'|'.$size[1].'|thumb f_l}'; } if ($block_prefix == 'e') { preg_match("/^e([0-9]+)/is", $block, $block_modifiers); $excerpt_length = $block_modifiers[1] ? $block_modifiers[1] : 80; $block_html = '

    {excerpt|'.$excerpt_length.'}

    '; } return $block_html; } // Маппинг блока function map_block($block_id, $gen_template, $size, $color = 'color1', $offset = 0) { global $blocks; define('MAX_DEEP_LEVEL', 10); if (!$color) $color = 'color1'; $size = explode('x', $size); $li_count = $size[0] * $size[1]; $li_size = $size[0]; $is_sb = true; $is_rb = false; $template = ''; for ($i = 0; $i < strlen($gen_template); $i++) { $char = substr($gen_template, $i, 1); if (strpos($gen_template, ' ') === false) $template .= $char.' '; else $template .= $char; if ($char == '(' || $char == ')') { $is_rb = true; $is_sb = false; } if ($char == '[' || $char == ']') { $is_rb = false; $is_sb = true; } } $template = trim($template); $template = str_replace('( ', '(', $template); $template = str_replace(' )', ')', $template); $template = str_replace('[ ', '[', $template); $template = str_replace(' ]', ']', $template); $template = str_replace(' {', '{', $template); $template = str_replace('{ ', '{', $template); $template = str_replace(' }', '}', $template); if ($is_rb) $template = '['.$template.']'; if ($is_sb) $template = '('.$template.')'; $template_blocks = array(); $template_sections = array(); for ($n = 0; $n < MAX_DEEP_LEVEL; $n++) { preg_match_all("/([\[\(]{1})([^\[\]\(\)]+)([\]\)]{1})/is", $template, $matches); foreach ($matches[2] as $i => $section) { $section_html = $section; $section = explode(' ', $section); $ob = $matches[1][$i]; $cb = $matches[3][$i]; foreach ($section as $block) { $block_html = map_block_prefix($block); if ($block_html != $block) { $template_block_id = ':'.mt_rand(100,999).mt_rand(100,999).mt_rand(1000,9999).':'; $template_blocks[$template_block_id] = $block_html; $section_html = str_replace($block, $template_block_id, $section_html); } } $section_prefix = ''; $section_postfix = ''; if ($ob == '[' && $cb == ']') { $section_prefix = ''; $section_postfix = ''; } $template_section_id = ':'.$section_prefix.mt_rand(100,999).mt_rand(100,999).mt_rand(10,99).$section_postfix.':'; $template_sections[$template_section_id] = $section_html; $template = str_replace($matches[0][$i], $template_section_id, $template); } } $replace_data = array(); for ($n = 0; $n < MAX_DEEP_LEVEL; $n++) { if (count($replace_data) > 0) break; foreach ($template_sections as $template_section_id => $template_section_html) { if (count($replace_data) > 0) break; if (strpos($template, $template_section_id) !== false) { $template_section_html = explode(' ', $template_section_html); $bracket = ''; if (strpos($template_section_id, '') !== false) { $bracket = ''; } $replace_data['bracket'] = $bracket; foreach ($template_section_html as $template_section) { if (strpos($template_section, $bracket) !== false) { $template_subsection_html = $template_sections[$template_section]; $template_subsection_html = explode(' ', $template_subsection_html); $replace_data[] = $template_subsection_html; } else { $replace_data[] = $template_section; } } } } } $template = ''; $template_span_count = 5; $bracket = $replace_data['bracket']; unset($replace_data['bracket']); // ()- вертикальное объединение в горизонтальном блоке if ($bracket == '') { if (is_array($replace_data[1])) { $template_span_count = count($replace_data[1]); $template .= ""; for ($i = 1; $i < count($replace_data[1]); $i++) { $template .= ""; } } if (is_array($replace_data[0])) { $template_span_count = count($replace_data[0]); $template .= ""; for ($i = 1; $i < count($replace_data[0]); $i++) { $template .= ""; } } } // [] - горизонтальное объединение в вертикальном блоке else { foreach ($replace_data as $key => $value) { if (is_array($value)) { $template_span_count = count($value); $template .= ''; foreach ($value as $subvalue) { $template .= ""; } $template .= ''; } else { $template .= ""; } } } $template .= '
    {$replace_data[0]}{$replace_data[1][0]}
    {$replace_data[1][$i]}
    {$replace_data[0][0]}{$replace_data[1]}
    {$replace_data[0][$i]}
    $subvalue
    $value
    '; $template = str_replace('rowspan="5"', 'rowspan="'.$template_span_count.'"', $template); $template = str_replace('colspan="5"', 'colspan="'.$template_span_count.'"', $template); for ($n = 0; $n < MAX_DEEP_LEVEL; $n++) { foreach ($template_sections as $template_section_id => $template_section) { $template = str_replace($template_section_id, $template_section, $template); } } for ($n = 0; $n < MAX_DEEP_LEVEL; $n++) { foreach ($template_blocks as $template_block_id => $template_block) { $template = str_replace($template_block_id, $template_block, $template); } } $return_html = ''; if ($block_id == 'slider') { $template = my_block(array( 'include' => $blocks[$block_id]['id'], 'count' => $li_count, 'template' => "
  • $template
  • " )); $return_html = "
    {$blocks[$block_id]['title']}
      {$template}
    "; } else { $template = my_block(array( 'category' => $blocks[$block_id]['id'], 'count' => $li_count, 'offset' => $offset, 'template' => "
  • $template
  • " )); $return_html = "
    {$blocks[$block_id]['title']}Далее »
      {$template}
    "; } return $return_html; } ?> Бытовка под ключ